package com.wsf.main.service;

import com.wsf.main.dto.OutAndInDTO;
import com.wsf.main.dto.TimeDTO;
import com.wsf.main.dto.UserDto;
import com.wsf.main.mapper.RecviceDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class RecviceDataService {
    @Autowired
    private RecviceDataMapper recviceDataMapper;


    public void insert(UserDto userDto) {
        recviceDataMapper.insertUser(userDto);
    }

    public int check(String enterOrExit, String certificateNum) {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        // 把日期往后增加一天,整数  往后推,负数往前移动
        calendar.add(Calendar.MINUTE, -1);
        // 这个时间就是日期往后推一天的结果
        date = calendar.getTime();
        int num=recviceDataMapper.check(enterOrExit,certificateNum,date,new Date());
        return num;
    }

    public List<Map<String, String>> getDeviceList() {
       return  recviceDataMapper.getDeviceList();
    }

    public List<Map<String, Object>> getUserList() {
        return  recviceDataMapper.getUserList();
    }

    public void updateUserStatus(UserDto userDto) {
        recviceDataMapper.updateUserStatus(userDto);
    }

    public void updateUserStatusAndTask(UserDto userDto) {
        recviceDataMapper.updateUserStatusAndTask(userDto);
    }

    public TimeDTO getTime() {
       return recviceDataMapper.getTime();
    }

    public void insertOutAndIn(List<OutAndInDTO> outAndInDTOList) {
        recviceDataMapper.insertOutAndIn(outAndInDTOList);
    }

    public List<UserDto> getUserListByNo(String jobNo,String eventTime) {
        return  recviceDataMapper.getUserListByNo(jobNo,eventTime);
    }

    public UserDto getUserByNo(String jobNo, String eventTime) {
        return  recviceDataMapper.getUserByNo(jobNo,eventTime);
    }

    public void updateTime(Date now) {
        recviceDataMapper.updateTime(now);
    }

    public void updateOutStatus(int id) {
        recviceDataMapper.updateOutStatus(id);
    }

    public List<OutAndInDTO> sendRecord() {
        return  recviceDataMapper.sendRecord();
    }

    public List<OutAndInDTO> sendRecord1(String time) {
        return  recviceDataMapper.sendRecord1(time);
    }
}
